// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
//导入axios
import axios from 'axios'



axios.interceptors.request.use(req=> {
    // 在发送请求之前做些什么
    req.baseURL="http://192.168.60.79:80"
    let token=localStorage.getItem("token");
    if(token){
      req.headers["token"]=token
    }
    return req;
});
axios.interceptors.response.use(resp=> {
if(resp.data.code=="401"){
  router.push("/adminlogin")
}

if(resp.data.code=="200"){
  //将服务器响应的token保存到本地localStorage中

  let token=resp.headers["token"];
  if(token){
    localStorage.setItem("token",token);
  }

}

    return resp;
});
Vue.prototype.$http=axios
Vue.use(ElementUI);
Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
